import Vue from 'vue'
import i18n from '@/i18n'
import 'normalize.css/normalize.css' // A modern alternative to CSS resets

import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'

import '@/styles/index.scss' // global css

import App from './App'
import store from './store'
import router from './router'
// 引入库

import '@/icons' // icon

import '@/permission' // permission control

/**
 * If you don't want to use mock-server
 * you want to use MockJs for mock api
 * you can execute: mockXHR()
 *
 * Currently MockJs will be used in the production environment,
 * please remove it before going online ! ! !
 */
// if (process.env.NODE_ENV === 'production') {
//   const { mockXHR } = require('../mock')
//   mockXHR()
// }

// 混入的用法
import mixin from '@/mixin'
Vue.mixin(mixin)

// set ElementUI lang to EN
Vue.use(ElementUI, { i18n: (key, value) => i18n.t(key, value) })
// 如果想要中文版 element-ui，按如下方式声明
// Vue.use(ElementUI)

import Component from '@/components'
Vue.use(Component) // 注册自己的插件

Vue.config.productionTip = false

// 全局自定义指令演示  Vue.directive(指令名,指令配置对象)
Vue.directive('fiximg', {
  inserted(el) {
    console.log(el)
    el.src = el.src || require('@/assets/common/head.jpg')
    el.addEventListener('error', () => {
      el.src = require('@/assets/common/head.jpg')
    })
  }
})

// 过滤器的全局注册
Vue.filter('formatDate', (oldVal) => {
  const date = new Date(oldVal)
  return date.toLocaleDateString()
})

import Print from 'vue-print-nb'
Vue.use(Print)
new Vue({
  el: '#app',
  router,
  store,
  i18n,
  render: h => h(App)
})
